import { defineComponent } from 'vue';

const camelizeRE = /-(\w)/g;
function camelize(str) {
  return str.replace(camelizeRE, (_, c) => c.toUpperCase());
}
function withInstall(options) {
  options.install = (app) => {
    const { name } = options;
    app.component(name, options);
    app.component(camelize(`-${name}`), options);
  };
  return options;
}

function gen(name, mods) {
  if (!mods) {
    return "";
  }
  if (typeof mods === "string") {
    return ` ${name}--${mods}`;
  }
  if (Array.isArray(mods)) {
    return mods.reduce((ret, item) => ret + gen(name, item), "");
  }
  return Object.keys(mods).reduce((ret, key) => ret + (mods[key] ? gen(name, key) : ""), "");
}
function createBEM(name) {
  return function(el, mods) {
    if (el && typeof el !== "string") {
      mods = el;
      el = "";
    }
    el = el ? `${name}__${el}` : name;
    return `${el}${gen(el, mods)}`;
  };
}

function createNamespace(name) {
  const prefixedName = `h-${name}`;
  return [
    prefixedName,
    createBEM(prefixedName)
  ];
}

const [name, bem] = createNamespace("button");
var _Button = defineComponent({
  name,
  props: {
    type: {
      type: String,
      require: false,
      default: "default"
    },
    size: {
      type: String,
      require: false,
      default: "normal"
    },
    color: {
      type: String,
      require: false,
      default: ""
    },
    text: {
      type: String,
      require: false,
      default: ""
    },
    disabled: {
      type: Boolean,
      require: false,
      default: false
    },
    onBtnClick: Function
  },
  setup(props, context) {
    const { color, type, size, text, disabled } = props;
    const classes = [bem([type, size, disabled ? "disabled" : ""])];
    return () => /* @__PURE__ */ React.createElement("div", {
      style: {
        background: color,
        border: color ? `1px solid ${color}` : ""
      },
      class: classes,
      onClick: (event) => disabled ? null : context.emit("btn-click", event)
    }, text);
  }
});

const Button = withInstall(_Button);

export default Button;
export { Button };
